package com.time.company.webserver.request;

import com.google.gson.Gson;
import com.time.company.servermodel.BasicBean;
import com.yanzhenjie.nohttp.Headers;
import com.yanzhenjie.nohttp.Logger;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.RestRequest;
import com.yanzhenjie.nohttp.rest.StringRequest;

/**s
 * <p>
 * 封装了业务逻辑层的状态的JavaBean，如果服务端的数据规则可使用这个，
 * 不过需要开发者把BasicBean改成和自己业务逻辑相符的JavaBean
 * </p>
 * Created by Bing on 2016/8/23.
 * E-mail is tx16bing@163.com
 */
public class BasicRequest extends RestRequest<BasicBean> {

    public BasicRequest(String url) {
        super(url, RequestMethod.POST);
    }

    public BasicRequest(String url, RequestMethod requestMethod) {
        super(url, requestMethod);
    }

    @Override
    public BasicBean parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
        String response = StringRequest.parseResponseString(responseHeaders, responseBody);
        Logger.i("Response application is " + response);
        try {
             return  new Gson().fromJson(response, BasicBean.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new BasicBean();
    }

}
